package com.ruoyi.cngj.controller.phone;

import com.ruoyi.cngj.domain.*;
import com.ruoyi.cngj.service.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.EmptyUtils;
import com.ruoyi.common.utils.IdWorker;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 轮播图Controller
 * 
 * @date 2024-06-27
 */
@Controller
@RequestMapping("/phone/cngj/website")
public class CngjWebsitePhoneController extends BaseController
{
    @Autowired
    private ICngjBannerService cngjBannerService;

    @Autowired
    private ICngjNewsService cngjNewsService;

    @Autowired
    private ICngjUserService cngjUserService;

    @Autowired
    private ICngjProjectService cngjProjectService;

    @Autowired
    private ICngjTzjService cngjTzjService;

    @Autowired
    private ICngjHonorService cngjHonorService;

    @Autowired
    private ICngjInformationService cngjInformationService;

    @Autowired
    private ICngjEnterpriseService cngjEnterpriseService;

    @Autowired
    private ICngjPostService cngjPostService;

    @Autowired
    private ISysDtAreaService sysDtAreaService;

    /**
     * 网站获取banner
     * @param type 分类 1首页轮播 2解决方案轮播 3产品中心轮播
     * @return
     * @throws Exception
     */
    @RequestMapping("/getWebBannerList")
    @ResponseBody
    public AjaxResult getWebBannerList(String type)throws Exception
    {
        CngjBanner banner = new CngjBanner();
//        banner.setBannerType(type);
        banner.setBannerState("1");
        Map params = new HashMap();
        params.put("type", type);
        banner.setParams(params);
        List<CngjBanner> list = cngjBannerService.selectCngjBannerList(banner);
        return AjaxResult.success("获取成功", list);
    }

    /**
     * 获取首页最新动态
     * @return
     * @throws Exception
     */
    @RequestMapping("/getWebHomeNewsList")
    @ResponseBody
    public AjaxResult getWebHomeNewsList()throws Exception
    {
        CngjNews news = new CngjNews();
        news.setNewsState("1");
        List<CngjNews> list = cngjNewsService.selectCngjNewsList(news);
        return AjaxResult.success("获取成功", list);
    }


    /**
     * 成为合作伙伴
     * @param userName
     * @param userCompany
     * @param userPhone
     * @param userProvince
     * @param userCity
     * @param userCounty
     * @return
     * @throws Exception
     */
    @RequestMapping("/saveUser")
    @ResponseBody
    public AjaxResult saveUser(String userName, String userCompany, String userPhone,
                               String userProvince, String userCity, String userCounty,
                               String userProvinceCode, String userCityCode, String userCountyCode)throws Exception
    {
        CngjUser user = new CngjUser();
        user.setId(IdWorker.getId());
        user.setUserName(userName);
        user.setUserCompany(userCompany);
        user.setUserPhone(userPhone);
        user.setUserProvince(userProvince);
        user.setUserCity(userCity);
        user.setUserCounty(userCounty);
        user.setUserProvinceCode(userProvinceCode);
        user.setUserCityCode(userCityCode);
        user.setUserCountyCode(userCountyCode);

        cngjUserService.insertCngjUser(user);
        return AjaxResult.success("操作成功");
    }


    /**
     * 获取项目案例
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @RequestMapping("/getWebProjectList")
    @ResponseBody
    public  AjaxResult getWebProjectList(String pageNum, String pageSize)throws Exception
    {

        CngjProject project = new CngjProject();
        project.setProjectState("1");
        List<CngjProject> listSize = cngjProjectService.selectCngjProjectList(project);

        Map map = new HashedMap();
        if(EmptyUtils.isNotEmpty(pageNum) && EmptyUtils.isNotEmpty(pageSize)){
            int num = Integer.valueOf(pageNum);
            int size = Integer.valueOf(pageSize);
            num = (num - 1) * size;
            map.put("beginPos", num);
            map.put("pageSize", size);
        }
        project = new CngjProject();
        project.setParams(map);
        project.setProjectState("1");
        List<CngjProject> list = cngjProjectService.selectCngjProjectList(project);
        map = new HashMap();
        map.put("list", list);
        map.put("listSize", listSize.size());
        return AjaxResult.success("获取成功", map);
    }

    /**
     * 获取探站记
     * @return
     * @throws Exception
     */
    @RequestMapping("/getWebTzjList")
    @ResponseBody
    public AjaxResult getWebTzjList()throws Exception
    {
        CngjTzj tzj = new CngjTzj();
        tzj.setTzjState("1");
        List<CngjTzj> list = cngjTzjService.selectCngjTzjList(tzj);
        return AjaxResult.success("获取成功", list);
    }

    /**
     * 获取新闻动态 分页
     * @param pageNum
     * @param pageSize
     * @return
     * @throws Exception
     */
    @RequestMapping("/getWebNewsList")
    @ResponseBody
    public  AjaxResult getWebNewsList(String pageNum, String pageSize)throws Exception
    {
        CngjNews news = new CngjNews();
        news.setNewsState("1");
        List<CngjNews> listSize = cngjNewsService.selectCngjNewsList(news);

        Map map = new HashedMap();
        if(EmptyUtils.isNotEmpty(pageNum) && EmptyUtils.isNotEmpty(pageSize)){
            int num = Integer.valueOf(pageNum);
            int size = Integer.valueOf(pageSize);
            num = (num - 1) * size;
            map.put("beginPos", num);
            map.put("pageSize", size);
        }
        news = new CngjNews();
        news.setParams(map);
        news.setNewsState("1");
        List<CngjNews> list = cngjNewsService.selectCngjNewsList(news);

        map = new HashMap();
        map.put("list", list);
        map.put("listSize", listSize.size());
        return AjaxResult.success("获取成功", map);
    }

    /**
     * 获取荣誉专利
     * @return
     * @throws Exception
     */
    @RequestMapping("/getWebHonorList")
    @ResponseBody
    public AjaxResult getWebHonorList()throws Exception
    {
        CngjHonor honor = new CngjHonor();
        honor.setHonorState("1");
        List<CngjHonor> list = cngjHonorService.selectCngjHonorList(honor);
        return AjaxResult.success("获取成功", list);
    }

    /**
     * 获取资料下载
     * @return
     * @throws Exception
     */
    @RequestMapping("/getWebInformationList")
    @ResponseBody
    public AjaxResult getWebInformationList()throws Exception
    {
        CngjInformation information = new CngjInformation();
        information.setInformationState("1");
        List<CngjInformation> list = cngjInformationService.selectCngjInformationList(information);
        return AjaxResult.success("获取成功", list);
    }

    /**
     * 获取企业情况展示
     * @return
     * @throws Exception
     */
    @RequestMapping("/getWebEnterpriseList")
    @ResponseBody
    public AjaxResult getWebEnterpriseList()throws Exception
    {
        CngjEnterprise enterprise = new CngjEnterprise();
        enterprise.setEnterpriseState("1");
        List<CngjEnterprise> list = cngjEnterpriseService.selectCngjEnterpriseList(enterprise);
        return AjaxResult.success("获取成功", list);
    }

    /**
     * 获取岗位列表
     * @return
     * @throws Exception
     */
    @RequestMapping("/getWebPostList")
    @ResponseBody
    public AjaxResult getWebPostList()throws Exception
    {
        CngjPost post = new CngjPost();
        post.setPostState("1");
        List<CngjPost> list = cngjPostService.selectCngjPostList(post);
        return AjaxResult.success("获取成功", list);
    }

    /**
     * 获取省市县
     * @param pid
     * @return
     */
    @RequestMapping("/getAreaByPid")
    @ResponseBody
    public AjaxResult getAreaByPid(String pid){
        pid = EmptyUtils.isEmpty(pid)?"0":pid;
        SysDtArea area = new SysDtArea();
        area.setAreaParentId(pid);
        return AjaxResult.success("获取成功", sysDtAreaService.selectSysDtAreaList(area));
    }

}
